# coding: utf-8
from constants import apb
from common.my_types import List, REN, Any


class DouPageProject:
    """我的项目"""
    
    def project_manage(self, stage: str = "", **kwargs):
        """我的项目
        Args:
            stage (str, optional): 项目类型, 全部类型"" 强排1 方案报建2 施工图3
        """
        point: str = "/project-manage/projects/search"
        payLoad: dict = {
            "stage": stage,
            "categoryName": kwargs.get("category_name", ""),
            "keyword": kwargs.get("keyword", ""),
            "myUpload": kwargs.get("my_upload", False),
            "pageIndex": kwargs.get("pageIndex", 1),
            "pageSize": kwargs.get("pageSize", 20)
        }
        projectManageResponse: REN = apb.dou_request("post", point, json=payLoad)
        projectManageValue: List[dict] = projectManageResponse.get("value").get("data")
        
        return projectManageValue

    def project_folders(self, project_id: str, **kwargs):
        """项目下的文件夹, 只返回文件夹类型
        Args:
            stage (str, optional): 项目类型, 全部类型"" 强排1 方案报建2 施工图3
        """
        point: str = f"/project-manage/projects/{project_id}/folders"
        projectFoldersResponse: REN = apb.dou_request("get", point)
        projectFoldersValue: List[dict] = projectFoldersResponse.get("value")
        
        return projectFoldersValue

    def project_folders_search(self, project_id: str, folder_id: int = 0, **kwargs):
        """项目下的文件夹, 包含所有类型
        Args:
            project_id (str): 项目id
            folder_id (int, optional): 文件夹id, default 0
        """
        point: str = f"/project-manage/projects/{project_id}/folders/search"
        payLoad: dict = {
            "folderId": folder_id,
            "projectId": project_id,
            "orderBy": kwargs.get("order_by", "create_time"),
            "pageIndex": kwargs.get("pageIndex", 1),
            "pageSize": kwargs.get("pageSize", 12)
        }
        projectFoldersSearchResponse: REN = apb.dou_request("post", point, json=payLoad)
        projectFoldersSearchValue: List[dict] = projectFoldersSearchResponse.get("value").get("data")
        
        return projectFoldersSearchValue

    def project_file_search(self, project_id: str, folder_id: int = 0, **kwargs):
        """文件夹下的所有文件
        Args:
            project_id (str): 项目id
            folder_id (int, optional): 文件夹id
        """
        point: str = f"/project-manage/projects/{project_id}/folders/search"
        payLoad: dict = {
            "folderId": folder_id,
            "projectId": project_id,
            "orderBy": kwargs.get("order_by", "create_time"),
            "pageIndex": kwargs.get("pageIndex", 1),
            "pageSize": kwargs.get("pageSize", 12)
        }
        projectFileSearchResponse: REN = apb.dou_request("post", point, json=payLoad)
        projectFilesSearchValue: List[dict] = projectFileSearchResponse.get("value").get("data")
        
        return projectFilesSearchValue

    def project_file_rename(self, file_id: str, new_name: str, **kwargs):
        """项目下的文件重命名
        Args:
            file_id (str): 文件id
            new_name (str, optional): 文件新名称
        """
        point: str = "/project-manage/projectItem/rename"
        payLoad: dict = {
            "id": file_id,
            "name": new_name
        }
        projectFileRenameResponse: REN = apb.dou_request("post", point, json=payLoad)
        projectFileRenameMessage: Any = projectFileRenameResponse.get("message")
        
        return projectFileRenameMessage
